package org.puremvc.as3.multicore.utilities.assetLoader.clients
{
	import flash.events.Event;
	
	
	import org.puremvc.as3.multicore.utilities.assetLoader.interfaces.ILoaderClientInfo;
	
	//TODO: security errors
	public class LoaderClientBase
	{
		private var mLoadInfo:ILoaderClientInfo;
		
		public function LoaderClientBase(cli:ILoaderClientInfo)
		{
			mLoadInfo = cli;
		}
		
		public final function load():void
		{
			initialiseLoad();
			addListeners();
			startLoad();
		}
			
		protected function initialiseLoad():void
		{
			throw new Error("this method must be overridden")
		}
		
		protected function addListeners():void{

			throw new Error("this method must be overridden")

		}
		
		protected function startLoad():void
		{
			throw new Error("this method must be overridden")
		}
		
		protected final function loadCompleteHandler(event:Event):void
		{
			removeListeners();
			prepareAsset(event);
			completedCallBack()
			relayHandler( event );
		}
		

		
		protected function removeListeners():void{

			throw new Error("this method must be overridden")

		}
		
		protected function prepareAsset(event:Event):void{

			throw new Error("this method must be overridden")

		}
		
		protected final function errorHandler(event:Event):void{
			
			removeListeners();
			handleError(event);
			
		}
		
		protected function handleError(event:Event):void
		{
			relayHandler(event);
		}
		
		protected final function relayHandler(event:Event):void{
			
			
			mLoadInfo.relayEvent(event);
			
		}
		
		protected final function completedCallBack():void{
			
			mLoadInfo.completedCallBack();
			
		}

		
		protected final function get loaderClientInfo():ILoaderClientInfo
		{ 
			return mLoadInfo
		}
		

		
		

	}
}